home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_shs_maindoor.cog < prev    next >
Text File  |  1999-11-15  |  12KB  |  390 lines

  1. # Jones 3D Cog Script
  2. #
  3. # Shs_Maindoor.cog      Make the door to the big nave open/close.  
  4. #
  5. # [JWC, SXC]
  6. #
  7. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  8. #
  9. # ========================================================================================
  10.  
  11. symbols
  12.  
  13.     message     activated
  14.     message        startup
  15.     message        touched
  16.     message        timer
  17.     message        arrived
  18.  
  19.     keyframe    leverDown=gen_lever_pull.key        local
  20.     keyframe    indypull=in_pull_lever.key            local
  21.  
  22.     sound        leverPull=nub_lever_pull_c.wav        local
  23.     sound        leverBack=nub_lever_reset_c.wav        local
  24.     sound       doormove=shs_door_double.wav        local
  25.     sound       doorstop=shs_door_double_stop.wav    local
  26.  
  27.  
  28.     sector      doorsector
  29.     sector        door0OpenSector                        local
  30.     sector        door1OpenSector                        local
  31.     sector        door0ClosedSector                    local
  32.     sector        door1ClosedSector                    local
  33.  
  34.     thing        door0
  35.     thing       door1
  36.     thing       lever
  37.     thing        indy
  38.     thing        in_mk1
  39.     thing        player                                local
  40.     thing        cam1
  41.     thing        c1_t1
  42.     thing        c1_t2
  43.     thing        touchedDoor                            local
  44.  
  45.     vector        v_dpos                                local # door position
  46.     vector        v_ipos                                local # indy position
  47.     vector        v_idvec                                local # indy-to-door vec
  48.     vector        v_drvec                                local # door right vec
  49.     vector        v_opendoor0PYR                        local
  50.     vector        v_opendoor1PYR                        local
  51.     vector        v_currentDoor0PYR                    local
  52.     vector        v_closedoor0PYR                        local # door aim
  53.     vector        v_closedoor1PYR                        local # door aim
  54.     vector        v_door0OpenPosition                    local
  55.     vector        v_door1OpenPosition                    local
  56.     vector        v_door0ClosedPosition                local
  57.     vector        v_door1ClosedPosition                local
  58.  
  59.     int            doorSound=-1                        local
  60.     int            pl_rotrate                            local
  61.     int            bCutscenePlayed=0                    local
  62.     int          filter=0                            local # prevent multiple activates    
  63.     int            curcam                                local
  64.     int            alreadytouched=0                    local
  65.     int            stopclose=0                            local # default to allow closing!
  66.     int            open=0                                local
  67.     # NOTE:  doors have 4 states...
  68.     # closed    --> open == 0 (init state)
  69.     # opening    --> open == 1
  70.     # open        --> open == 2
  71.     # closing    --> open == 3
  72.  
  73.     flex        f_arrdoorY                            local # door yaw at arrival
  74.     flex        f_iposcheck                            local # dot result indy relative to door
  75.     flex        touchangle                            local
  76.     flex        closeangle                            local
  77.     flex        reopenangle                            local
  78.     flex        timeratio                            local
  79.     flex        reopentime                            local
  80.     flex        doortime=4.0                        local
  81.     flex        timeTillClose=15.0                    local
  82.  
  83. # SUB-ROUTINES
  84.     flex        ReturnControl    local
  85.     flex        CloseDoors        local
  86.     flex        OpenDoors        local
  87.  
  88. end
  89.  
  90. # ========================================================================================
  91.  
  92. code
  93.  
  94.  
  95. startup:
  96.    
  97.     #turn off sector
  98.     SetSectorAdjoins(doorsector, 0);
  99.     player= GetLocalPlayerThing();
  100.  
  101.     // Save off the position, PYR, and sector of the door when closed.
  102.  
  103.     v_closedoor0PYR = GetThingLVecPYR(door0);
  104.     v_closedoor1PYR = GetThingLVecPYR(door1);
  105.     v_door0ClosedPosition = GetThingPos(door0);
  106.     v_door1ClosedPosition = GetThingPos(door1);
  107.     door0ClosedSector = GetThingSector(door0);
  108.     door1ClosedSector = GetThingSector(door1);
  109.  
  110.     // Now compute the PYR of the door when it's open.
  111.  
  112.     v_opendoor0PYR = VectorSet(VectorX(v_closedoor0PYR), VectorY(v_closedoor0PYR) + 90, VectorZ(v_closedoor0PYR));
  113.     v_opendoor1PYR = VectorSet(VectorX(v_closedoor1PYR), VectorY(v_closedoor1PYR) - 90, VectorZ(v_closedoor1PYR));
  114.  
  115.     return;
  116.  
  117. activated:
  118.    
  119.     if (GetCurItem(player) != 0)
  120.         return;                                # prevents activating with chalk
  121.  
  122.     if ((GetSenderRef() == lever) && (filter == 0))
  123.     {
  124.         pl_rotrate = GetThingMaxRotVel(player);
  125.         filter = 1;                            // Only one activate message at a time, please.
  126.         curCam = GetCurrentCamera();
  127.         StartCutscene(0);
  128.         SetActorFlags(player, 0x200000);    # paralyze him
  129.  
  130.         # Disable and hide player...
  131.         StopThing(player);                    # right now
  132.         PlayMode(player, 1, 0);                # get him into a nice stand
  133.         DeselectWeapon(player);                # stow any weapon or lighter
  134.         DeselectWeaponWait(player);
  135.         CopyPlayerHolsters(player, indy);    # make sure our actor has matching props
  136.         Sleep(0.5);                            # give him some time to do his stuff
  137.         
  138.         
  139.         # Prep camera & cut...
  140.         SetCameraLookInterp(2, 0);            # kill pan & tilt to lock on 2nd target
  141.         SetCameraPosInterp(2, 0);            # kill dolly mode too
  142.         SetCameraFocus(2, cam1);
  143.         SetCameraSecondaryFocus(2, c1_t1);
  144.         Sleep(0.01);
  145.         SetCurrentCamera(2);
  146.         SetCameraFOV(65, 0, 0.0);
  147.         
  148.         # Switch actor indy for player...
  149.         SetThingFlags(player, 0x80000);        # hide him
  150.         ClearThingFlags(indy, 0x80000);        # reveal our actor
  151.                 
  152.         # Indy pulls lever
  153.         PlayKey(indy, indypull, 4, 0x12, 0);
  154.         PlayKey(lever, leverDown, 4, 0x12, 0);
  155.         Sleep(1.2);
  156.         PlaySoundLocal(leverPull, 1.0, 0, 0x0000, 0);
  157.         Sleep(1.4);
  158.         PlaySoundLocal(leverBack, 1.0, 0, 0x0000, 0);
  159.         Sleep(0.3);
  160.  
  161.         if (!bCutscenePlayed)
  162.         {
  163.             // Only show the doors opening the first time the player pulls the lever.
  164.             # camera moves to show doors opening
  165.             SetCameraLookInterp(2, 1);            # pan & tilt 
  166.             SetCameraInterpSpeed(2, 3.0);
  167.             Sleep(0.01);
  168.             SetCameraSecondaryFocus(2, c1_t2);
  169.             SetCameraFOV(80, 1, 3.0);
  170.             Sleep(2.0); #start before move finishes
  171.         
  172.             # Look at door
  173.             SetThingMaxRotVel(indy, 100.0);
  174.             AISetLookThingEyeLevel(indy, door0);
  175.         }
  176.  
  177.         SetSectorAdjoins(doorsector, 1);
  178.         
  179.         # open doors                         
  180.         Call OpenDoors;
  181.         SetTimer(timeTillClose);        // Timer message will close doors automatically.
  182.  
  183.         if (!bCutscenePlayed)
  184.         {
  185.             // If we're showing the doors, wait 'till they finish opening before returning control to player.
  186.             WaitForStop(door0);
  187.             bCutscenePlayed = 1;
  188.         }
  189.  
  190.         Call ReturnControl;
  191.  
  192.         filter = 0;                        // Activate messages are cool again
  193.     }
  194.                  
  195.     return;
  196.     
  197. ReturnControl:
  198.        
  199.     # Return control and camera to player
  200.     sleep(.5);
  201.     SetActorHeadPYR(indy,'0,0,0');        # reset actor head
  202.     CopyOrientAndPos(indy, player); # move player to actor's spot
  203.     SetThingFlags(indy, 0x80000);
  204.     TeleportThing(indy, in_mk1);    # put actor back in spot
  205.     SetThingMaxRotVel(indy, pl_rotrate);
  206.     
  207.     # prep for camera to swing back
  208.     SetCameraPosition(1, VectorAdd(VectorTransformToOrient(player, '-0.25 -0.1 0.0'), GetThingPos(player)));     # x= -.25 means the camera is on the left
  209.     ClearThingFlags(player, 0x80000);
  210.     SetCameraLookInterp(2, 0); # kill pan & tilt mode
  211.     SetCameraPosInterp(2, 0); # kill dolly mode
  212.     Sleep(0.01);
  213.     SetCurrentCamera(1);
  214.     ResetCameraFOV(0, 0.0);
  215.     EndCutscene();
  216.     ClearActorFlags(player, 0x200000);
  217.     
  218.     return;
  219.  
  220. arrived:
  221.     if ((GetSenderRef() == door0) && open == 1)
  222.     {
  223.         // The doors were opening and have arrived.
  224.  
  225.         v_currentDoor0PYR = GetThingLVecPYR(door0);
  226.         f_arrdoorY = Truncate(VectorY(v_currentDoor0PYR)); # to lowest integer degree
  227.         if (f_arrdoorY == 90)
  228.         {
  229.             // We're fully open, time to slam the position and orientation of the doors.
  230.             if (!bCutscenePlayed)
  231.             {
  232.                 // This is the first time the doors have opened, so just save off the PYR and pos.
  233.                 v_door0OpenPosition = GetThingPos(door0);
  234.                 v_door1OpenPosition = GetThingPos(door1);
  235.                 door0OpenSector = GetThingSector(door0);
  236.                 door1OpenSector = GetThingSector(door1);
  237.             }
  238.             else
  239.             {
  240.                 // Doors have opened before, force them to previous position and orientation.
  241.                 SetThingPosEx(door0, v_door0OpenPosition, door0OpenSector);
  242.                 SetThingPosEx(door1, v_door1OpenPosition, door1OpenSector);
  243.                 SetThingLVecPYR(door0, v_opendoor0PYR); # slam it open for sure
  244.                 SetThingLVecPYR(door1, v_opendoor1PYR); # slam it open for sure
  245.             }
  246.  
  247.             open = 2; # doors are now open
  248.             StopSound(doorSound, 0.5);
  249.             doorSound = PlaySoundThing(doorstop, door0, 1.0, 4, 8, 0);
  250.         }
  251.  
  252.         SetTimer(timeTillClose);
  253.         return;
  254.     }
  255.  
  256.     if ((GetSenderRef() == door0) && open == 3)
  257.     {        
  258.         // The doors were closing and have arrived.
  259.  
  260.         if (alreadytouched == 1)
  261.         {
  262.             return;
  263.         }
  264.  
  265.         v_currentDoor0PYR = GetThingLVecPYR(door0);
  266.         f_arrdoorY = Truncate(VectorY(v_currentDoor0PYR)); # to lowest integer degree
  267.         if (f_arrdoorY == 0)
  268.         {
  269.             // We're fully closed, time to slam the position and orientation of the doors.
  270.  
  271.             SetThingLVecPYR(door0, v_closedoor0PYR); # slam it closed for sure
  272.             SetThingLVecPYR(door1, v_closedoor1PYR); # slam it closed for sure
  273.             SetThingPosEx(door0, v_door0ClosedPosition, door0ClosedSector);
  274.             SetThingPosEx(door1, v_door1ClosedPosition, door1ClosedSector);
  275.         }
  276.  
  277.         open = 0; # door is now closed
  278.         StopSound(doorSound, 0.5);
  279.         doorSound = PlaySoundThing(doorstop, door0, 1.0, 4, 8, 0);
  280.         SetSectorAdjoins(doorsector, 0);
  281.     }
  282.  
  283.     return;
  284.  
  285. # ..............................................................................
  286.  
  287. touched:
  288.     if ((GetSenderRef() == door0 || GetSenderRef() == door1) && open == 3 && alreadytouched == 0)
  289.     {
  290.         // The player has run into us, see if we need to re-open the doors.
  291.  
  292.         touchedDoor = GetSenderRef();
  293.         alreadytouched = 1;                                    # suppress multiple hits
  294.  
  295.         # check if Indy is touching back side of door...
  296.         v_dpos = GetThingPos(touchedDoor);                    # Position of door
  297.         v_ipos = GetThingPos(player);                        # our hero
  298.          v_idvec = VectorNorm(VectorSub(v_dpos, v_ipos));    # direction between indy & door 
  299.         v_drvec = GetThingLVec(touchedDoor);                # check 90 to door plane
  300.         f_iposcheck = VectorDot(v_idvec, v_drvec); # places indy in- or outside door
  301.  
  302.         if (((GetSenderRef() == door0) && (f_iposcheck < 0)) || ((GetSenderRef() == door1) && (f_iposcheck > 0)))
  303.         {
  304.             # Don't re-open if Indy is touching back side...
  305.             alreadytouched = 0;
  306.             return;
  307.         }
  308.  
  309.         // Indy is in the way - better re-open...            
  310.  
  311.         StopThing(door0);    # but first we stop it
  312.         StopThing(door1);    # but first we stop it
  313.         Sleep(0.1);            # let engine update
  314.         open = 1;            # door is going to open again
  315.  
  316.         # Get door angle at moment it's touched...
  317.  
  318.         v_currentDoor0PYR = GetThingLVecPYR(door0);
  319.         closeangle = VectorY(v_closedoor0PYR);
  320.         touchangle = VectorY(v_currentDoor0PYR);
  321.  
  322.         # Get rotation angle door needs to fully re-open...    
  323.         # PRO TIP:  the engine uses angles *backwards* from the Rotate() verb    
  324.  
  325.         reopenangle = ((closeangle + 90) - touchangle); # for L-doors 
  326.         if (reopenangle < -360)
  327.         {
  328.             reopenangle = (reopenangle + 360);
  329.         }
  330.  
  331.         # How far open...?
  332.         timeratio = (Abs(reopenangle) / 90); # what percentage?
  333.         reopentime = (doortime * timeratio); # calculate time
  334.  
  335.         StopSound(doorSound, 0.5);
  336.         doorSound = PlaySoundThing(doormove, door0, 1.0, 4, 8, 0);
  337.         Rotate(door0, -reopenangle, 1, reopentime); # re-open 
  338.         Rotate(door1,  reopenangle, 1, reopentime); # re-open 
  339.     }
  340.  
  341.     return;
  342.  
  343. timer:
  344.     if (stopclose != 0)
  345.     {
  346.         # Don't close door, but start the timer again...
  347.         SetTimer(2.0); # this amounts to a pulse
  348.         return;
  349.     }
  350.  
  351.     Call CloseDoors;
  352.  
  353.     return;
  354.  
  355. # ..............................................................................
  356.  
  357. OpenDoors:
  358.     if (open == 0)
  359.     {
  360.         Rotate(door0, -90, 1, doortime);
  361.         Rotate(door1,  90, 1, doortime);
  362.  
  363.         StopSound(doorSound, 0.5);
  364.         doorSound = PlaySoundThing(doormove, door0, 1.0, 4, 8, 0);
  365.         open = 1;
  366.         alreadytouched = 0; # init every time door opens
  367.     }
  368.  
  369.     return;
  370.  
  371. # ..............................................................................
  372.  
  373. CloseDoors:
  374.     if (open == 2)
  375.     {
  376.         Rotate(door0,  90, 1, doortime);
  377.         Rotate(door1, -90, 1, doortime);
  378.  
  379.         StopSound(doorSound, 0.5);
  380.         doorSound = PlaySoundThing(doormove, door0, 1.0, 4, 8, 0);
  381.         open = 3;
  382.         alreadytouched = 0; # Indy can stop it again
  383.     }
  384.  
  385.     return;
  386.  
  387. # ..............................................................................
  388. end
  389.  
  390.